home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-09 | 4.5 KB | 210 lines | [TEXT/PJMM] |
- { TinyEdit - Minimal TransEdit Demonstration.}
-
- { The project should include TinyEdit.p (this file), TransEdit.p,}
- { FakeAlert.p, TransSkel.p (or a library made from TransSkel.p)}
- { Runtime.lib and Interface.lib. Also, in the Run options dialog, set}
- { the resource file to use to be TinyEdit.proj.rsrc. }
-
- { 8 November 1986 Paul DuBois}
-
- { 8 January 1987 Ported to LightSpeed Pascal by Owen Hartnett }
- { Ωhm Software Company, 163 Richard Drive, Tiverton, RI 02878 }
- { 2 December 1988 Made modifications for LSP 2.0 - OH }
-
- program TinyEdit;
-
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf,
- {$ENDC}
- TransEdit, TransSkel;
-
- const
- aboutAlrt = 1000; { "About..." alert number }
-
- { File menu item numbers }
-
- new = 1; { begin new window }
- open = 2; { open existing file }
- close = 3; { close window }
- quit = 5;
-
- { Edit menu item numbers }
-
- undo = 1;
- cut = 3;
- copy = 4;
- paste = 5;
- clear = 6;
-
- var
- lastFront, editWind: WindowPtr; { keeps track of front window }
- { non-nil if edit window open }
-
- fileMenu, editMenu: MenuHandle;
-
- dummy: boolean; { may be used for memory mngment }
- { Set File/Edit menu items according to type of front window.}
-
- { The general behavior is:}
-
- { New and Open enabled if an edit window is not open, otherwise they}
- { are disabled.}
-
- { Close enabled when an edit or DA window is in front (i.e.,}
- { when there's a window at all).}
-
- { Undo disabled when the edit window is in front.}
-
- procedure SetMenus;
-
- begin
- DisableItem(fileMenu, close); { assume no window at all }
- EnableItem(editMenu, undo);
-
- if FrontWindow <> nil then
- begin
- EnableItem(fileMenu, close);
- if (IsEWindow(FrontWindow)) then { the edit window's in front }
- DisableItem(editMenu, undo);
- end;
- if editWind = nil then
- begin
- EnableItem(fileMenu, new);
- EnableItem(fileMenu, open);
- end
- else
- begin
- DisableItem(fileMenu, new);
- DisableItem(fileMenu, open);
- end;
- end;
-
- { Got an activate or deactivate. It doesn't matter which, really.}
- { Set the text menus appropriately for the front window, and draw}
- { the menu bar, as these menus might change state from enabled to}
- { disabled or vice-versa.}
-
-
- procedure Activate (active: Boolean);
-
- begin
- SetMenus;
- end;
-
- { Close selected from File menu, or close box of edit window was}
- { clicked.}
-
- procedure myClose;
-
- begin
- if (EWindowClose(editWind)) then
- editWind := nil;
- SetMenus;
- end;
-
- { Make a new edit window. Set the title to "Untitled" if not bound}
- { to file, so that the window titling works the same whether}
- { TransEdit is compiled in single or multiple window mode.}
-
- procedure MakeWind (bindToFile: Boolean);
-
- var
- r: Rect;
-
- begin
- SetRect(r, 4, 45, 504, 335);
- editWind := NewEWindow(r, '', false, WindowPtr(-1), true, longint(0), bindToFile);
- if editWind <> nil then
- begin
- if not bindToFile then
- SetWTitle(editWind, 'Untitled');
- ShowWindow(editWind);
- end;
- end;
-
- { File menu handler}
-
- procedure DoFileMenu (item: integer);
-
- var
- theWind: WindowPtr;
- myPeek: WindowPeek;
-
- begin
- theWind := FrontWindow;
- case item of
- new:
- MakeWind(false);
- open:
- MakeWind(true);
- close:
- if IsEWindow(theWind) then
- myClose
- else
- begin
- myPeek := WindowPeek(theWind);
- CloseDeskAcc(myPeek^.windowKind);
- end;
- quit:
- if ClobberEWindows = true then
- SkelWhoa;
- otherwise
- end;
- SetMenus;
- end;
-
- { Handle selection of About… item from Apple menu}
-
- procedure DoAbout;
-
- var
- ignore: integer;
-
- begin
- ignore := Alert(aboutAlrt, nil);
- end;
-
- { Background procedure. Check front window, reset menus if it}
- { changes.}
-
- procedure CheckFront;
-
- begin
- if FrontWindow <> lastFront then
- begin
- SetMenus;
- lastFront := FrontWindow;
- end;
- end;
-
- begin
- lastFront := nil;
- editWind := nil;
-
- { Initialize TransSkel, create menus and install handlers.}
-
- SkelInit(6, nil);
- TransEditInit;
- SkelApple('About TinyEdit...', @DoAbout);
-
- fileMenu := NewMenu(1000, 'File');
- AppendMenu(fileMenu, 'New/N;Open.../O;(Close/W;(-;Quit/Q');
- dummy := SkelMenu(fileMenu, @DoFileMenu, nil, false);
-
- editMenu := NewMenu(1001, 'Edit');
- AppendMenu(editMenu, 'Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear');
- dummy := SkelMenu(editMenu, @EWindowEditOp, nil, true);
-
- { Do TransEdit-specific setup: set creator for any files created,}
- { set default event notification procedures for new windows.}
-
- SetEWindowProcs(nil, nil, @Activate, @myClose);
-
- { Process events until user quits,}
- { then clean up and exit}
-
- SkelBackground(@CheckFront);
- SkelMain;
- SkelClobber;
- end.